﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.OleDb;

namespace SAHCPIMS
{
    public partial class ADDPRENATAL : Form
    {
        /** GLOBAL VARIABLES :: being accessed by other forms :: **/
        public int familyNo;
        public string fname;
        public string mName;
        public string sname;
        public string bday;
        public string checkuptype;

        public string empnum;
        public string empname;
        public string promptS;


        public ADDPRENATAL()
        {
            InitializeComponent();
        }

        private void ADDPRENATAL_Load(object sender, EventArgs e)
        {
            this.familyNumberMismo.Text = familyNo.ToString();
            this.familyInformationLabel.Text = fname + " " + mName + " " + sname;
            this.bDateInfo.Text = bday;
            this.checkupTypeInfo.Text = checkuptype;
            this.checkupDate.Text = DateTime.Now.ToShortDateString();
            this.prompt.Text = promptS;
            this.empNumLabel.Text = empnum;
            this.employeeLabel.Text = empname;

            //int doFlag = 0;

            
        }

        private void logOutButton_Click(object sender, EventArgs e)
        {
            LOGIN logout = new LOGIN();
            logout.Visible = true;
            this.Visible = false;
        }

        private void homebutton_Click(object sender, EventArgs e)
        {
            HOME home = new HOME();
            home.Visible = true;
            this.Visible = false;
        }

        private void acceptbutton_Click(object sender, EventArgs e)
        {
            //Connection String
            string conString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=..\\SAHCPIMS_database.mdb";
            OleDbConnection conn = new OleDbConnection(conString);
            DataSet ds = new DataSet();
            //opens the connection to the database
            conn.Open();
            //try to add entry in the Vaccine table
            try
            {
                OleDbDataAdapter tagalagay = new OleDbDataAdapter("Insert into Prenatal values ('"
                    + familyNo + "','" + fname + "','" + mName + "','" + sname + "','" + DateTime.Now.ToShortDateString() + "','"
                    + this.xpcted.Text + "','" + this.aog.Text + "','" + this.lmp.Text + "','" + this.gravida.Text
                    + "','" + this.para.Text + "')", conn);
                tagalagay.Fill(ds);
                //doFlag = 0;
            }
            catch (OleDbException)
            {
                this.prompt.Text = "Data Already Exist";
               // doFlag = 1;
            }
            try
            {
                OleDbDataAdapter tagalagay = new OleDbDataAdapter("Insert into ToxoidPrenatal values ('"
                    + familyNo + "','" + fname + "','" + mName + "','" + sname + "','" + this.gravida.Text+"','" 
                    + DateTime.Now.ToShortDateString() + "')", conn);
                tagalagay.Fill(ds);
                //doFlag = 0;
            }
            catch (OleDbException)
            {
                this.prompt.Text = "Data Already Exist";
                // doFlag = 1;
            }
            conn.Close();
            HOME home = new HOME();
            home.Visible = true;
            this.Visible = false;
        }

    }
}
